package com.itheima.user.controller;

import com.itheima.entity.dto.LocationDto;
import com.itheima.entity.vo.Result;
import com.itheima.user.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.web.bind.annotation.*;

/**
 * @author :WuJunJie
 * creationTime :2022-12-14 19:33
 */
@RestController
@RequestMapping("/userService/location")
public class LocationController {
    @Autowired
    private LocationService locationService;


    @PostMapping
    public Result insertLocation(@RequestBody LocationDto locationDto) {
        Boolean insert = locationService.insertLocation(locationDto);
        if (insert) {
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping
    public Result selectLocation(@RequestBody LocationDto locationDto) {
        GeoResults<RedisGeoCommands.GeoLocation<String>> geoResults = locationService.selectLocation(locationDto);
        return Result.success(geoResults);
    }

}
